function lengthen(scale, direction, value, copyMove, autoAutoIncrement) {
  var drawingScale = scale;
  var ifCopyAndMove = copyMove;
  var ifAutoIncrement = autoAutoIncrement;
  // 转换单位
  // 转换成米
  function pointToM(numIn) {
    return (((numIn / 72) * 25.4) / 1000) * drawingScale;
  }
  // 转换成点
  function MTopoint(numIn) {
    return (((numIn * 1000) / 25.4) * 72) / drawingScale;
  }
  // 格式化数字
  function formatNumForJudge(numIn) {
    return parseFloat(trimEndZero(formatNum(pointToM(numIn), 2)));
  }
  if (documents.length > 0) {
    var activeDocument = app.activeDocument;
    var elementsSelected = activeDocument.selection;
    if (elementsSelected.length > 0) {
      for (i = 0; i < elementsSelected.length; i++) {
        var targetItem = elementsSelected[i];
        var distance = MTopoint(value / 100);
        switch (direction) {
          case 2:
            if (ifCopyAndMove) {
              newItem = targetItem.duplicate();
              targetItem.selected = false;
              newItem.selected = true;
              newItem.top -= distance;
              if (ifAutoIncrement) {
                var name = targetItem.name;
                if (name != "" || (name == "" && targetItem.typename == "TextFrame")) {
                  if (targetItem.typename == "TextFrame") {
                    name = targetItem.contents;
                  }
                  var newName = parseInt(name) + 1;
                  newItem.name = newName;
                  if (newItem.typename == "TextFrame") {
                    newItem.contents = newName;
                  }
                }
              }
            } else {
              targetItem.top -= distance;
            }
            break;
          case 4:
            if (ifCopyAndMove) {
              newItem = targetItem.duplicate();
              targetItem.selected = false;
              newItem.selected = true;
              newItem.left -= distance;
              if (ifAutoIncrement) {
                var name = targetItem.name;
                if (name != "" || (name == "" && targetItem.typename == "TextFrame")) {
                  if (targetItem.typename == "TextFrame") {
                    name = targetItem.contents;
                  }
                  var newName = parseInt(name) + 1;
                  newItem.name = newName;
                  if (newItem.typename == "TextFrame") {
                    newItem.contents = newName;
                  }
                }
              }
            } else {
              targetItem.left -= distance;
            }
            break;
          case 5:
            newItem = targetItem.duplicate();
            targetItem.selected = false;
            newItem.selected = true;
            break;
          case 6:
            if (ifCopyAndMove) {
              newItem = targetItem.duplicate();
              targetItem.selected = false;
              newItem.selected = true;
              newItem.left += distance;
              if (ifAutoIncrement) {
                var name = targetItem.name;
                if (name != "" || (name == "" && targetItem.typename == "TextFrame")) {
                  if (targetItem.typename == "TextFrame") {
                    name = targetItem.contents;
                  }
                  var newName = parseInt(name) + 1;
                  newItem.name = newName;
                  if (newItem.typename == "TextFrame") {
                    newItem.contents = newName;
                  }
                }
              }
            } else {
              targetItem.left += distance;
            }
            break;
          case 8:
            if (ifCopyAndMove) {
              newItem = targetItem.duplicate();
              targetItem.selected = false;
              newItem.selected = true;
              newItem.top += distance;
              if (ifAutoIncrement) {
                var name = targetItem.name;
                if (name != "" || (name == "" && targetItem.typename == "TextFrame")) {
                  if (targetItem.typename == "TextFrame") {
                    name = targetItem.contents;
                  }
                  var newName = parseInt(name) + 1;
                  newItem.name = newName;
                  if (newItem.typename == "TextFrame") {
                    newItem.contents = newName;
                  }
                }
              }
            } else {
              targetItem.top += distance;
            }
            break;
        }
        // targetItem.selected = false;
      }
    } else {
      alert("请先选中一个物体!");
    }
  } else {
    alert("请先打开一个文档!");
  }
}

function formatNum(numIn, accuracyIn) {
  var tempNum = numIn.toFixed(accuracyIn + 2).slice(0, -1);
  var tempNumString = "" + tempNum;
  var lastNum = parseInt(tempNumString.charAt(tempNumString.length - 1));
  if (lastNum != 0) {
    var zeroString = "";
    var tempString = "";
    for (k = 1; k < accuracyIn; k++) {
      zeroString += "0";
    }
    tempString = "0." + zeroString + "1";
    // 此时area为字符串
    numIn = numIn.toFixed(accuracyIn + 1).slice(0, -1);
    numIn = parseFloat(numIn) + parseFloat(tempString);
  } else {
    numIn = numIn.toFixed(accuracyIn + 1).slice(0, -1);
  }
  return numIn;
}

function trimEndZero(numIn) {
  var originString = "" + numIn;
  numIn = parseFloat(originString);
  return numIn;
}
